1   // Copyright 2008, 2009, 2010 The Apache Software Foundation
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   // http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package org.apache.tapestry5.integration.pagetester;
16  
17  import org.apache.tapestry5.dom.Document;
18  import org.apache.tapestry5.integration.pagelevel.TestConstants;
19  import org.apache.tapestry5.internal.InternalSymbols;
20  import org.apache.tapestry5.ioc.services.SymbolSource;
21  import org.apache.tapestry5.test.PageTester;
22  import org.testng.Assert;
23  import org.testng.annotations.AfterClass;
24  import org.testng.annotations.BeforeClass;
25  import org.testng.annotations.DataProvider;
26  import org.testng.annotations.Test;
27  
28  import java.util.Collections;
29  import java.util.Map;
30  
31  /**
32   * Tests on PageTester itself.
33   */
34  public class PageTesterTest extends Assert
35  {
36      private PageTester nonEmptyAppNameTester;
37      
38      private PageTester emptyAppNameTester;
39      
40      @BeforeClass
41      public void setup()
42      {
43          nonEmptyAppNameTester = new PageTester(TestConstants.APP2_PACKAGE, TestConstants.APP2_NAME, "src/test/app2");
44          
45          emptyAppNameTester = new PageTester(TestConstants.APP2_PACKAGE, "", "src/test/app2");
46      }
47  
48      @AfterClass
49      public void cleanup()
50      {
51          nonEmptyAppNameTester.shutdown();
52  
53          nonEmptyAppNameTester = null;
54          
55          emptyAppNameTester.shutdown();
56  
57          emptyAppNameTester = null;
58      }
59      
60      @DataProvider(name = "testers")
61      public Object[][] getTesters()
62      {
63          return new Object[][] { { nonEmptyAppNameTester }, { emptyAppNameTester } };
64      }
65  
66      @Test(dataProvider = "testers")
67      public void on_activate_chain_is_followed(PageTester tester)
68      {
69          Document launchDoc = tester.renderPage("Launch");
70  
71          Map<String, String> parameters = Collections.emptyMap();
72  
73          // Submit the form, which will then skip through Intermediate and
74          // arrive at Final.
75  
76          Document finalDoc = tester.submitForm(launchDoc.getElementById("form"), parameters);
77  
78          assertEquals(finalDoc.getElementById("page-name").getChildMarkup(), "Final");
79      }
80  
81      @Test(dataProvider = "testers")
82      public void application_path_is_defined_as_a_symbol(PageTester tester)
83      {
84          SymbolSource source = tester.getRegistry().getService(SymbolSource.class);
85  
86          assertEquals(source.valueForSymbol(InternalSymbols.APP_PACKAGE_PATH), "org/apache/tapestry5/integration/app2");
87      }
88  }